package com.ruoyi.business.service;

import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * 所有activiti7 业务流程操作服务层
 */
public interface IProcessService {
    /**
     * 流程部署
     * @param filePath
     * @return
     */
    Deployment deploy(String filePath) throws IOException;

    /**
     * 通过部署id查询流程定义对象
     * @param deploymentId
     * @return
     */
    ProcessDefinition selectProcessDefinitionByDeploymentId(String deploymentId);

    /**
     * 后去流程xml
     * @param deploymentId
     * @param resourceName
     * @return
     */
    InputStream getResourceAsStream(String deploymentId, String resourceName);

    /**
     *  获取流程图
     * @param processDefinitionId
     * @param highLightedActivities
     * @param highLightedFlows
     * @return
     */
    InputStream getProcessImage(String processDefinitionId,
                                List<String> highLightedActivities,
                                List<String> highLightedFlows);


    /**
     * 启动套餐审核流程
     * @param definitionKey
     * @param businessKey
     * @param map
     * @return
     */
    ProcessInstance startProcessInstanceByKey(String definitionKey,
                                              String businessKey, Map<String, Object> map);

    /**
     * 通过流程实例获取当前执行节点对象
     * @param instanceId
     * @return
     */
    Task getTaskByInstanceId(String instanceId);

    /**
     * 添加节点候选人
     * @param taskId
     * @param userId
     */
    void addCandidateUser(String taskId, String userId);

    /**
     * 查询高亮显示节点
     * @param instanceId
     * @return
     */
    List<String> getActiveActivityIds(String instanceId);

    /**
     * 删除审核流程
     * @param instanceId
     * @param msg
     */
    void deleteProcessInstance(String instanceId, String msg);

    /**
     * 查询指定参数todo task 任务(分页)
     *
     * @param definitionKey
     * @param userId
     * @param startNum
     * @param pageSize
     * @return
     */
    List<Task> selectTodoTaskList(String definitionKey, String userId,Integer startNum, Integer pageSize);

    /**
     * 获取指定id 流程实例
     * @param processInstanceId
     * @return
     */
    ProcessInstance getProcessInstanceById(String processInstanceId);

    /**
     * 获取待办任务个数
     * @param definitionKey
     * @param toString
     * @return
     */
    Long selectTodoTaskCount(String definitionKey, String toString);

    /**
     * 查询任务
     * @param taskId
     * @return
     */
    Task getTaskById(String taskId);

    /**
     * 领取任务并执行任务
     * @param task
     * @param userId
     * @param auditStatus
     * @param comment
     */
    void claimAndComplete(Task task, String userId ,Boolean auditStatus, String comment);

    /**
     * 设置流程变量
     * @param task
     * @param name
     * @param value
     */
    void setVariable(Task task, String name, Object value);

    /**
     * 查询task历史列表(带分页)
     * @param definitionKey
     * @param userId
     * @param startNum
     * @param pageSize
     * @return
     */
    List<HistoricTaskInstance> selectDoneTaskList(String definitionKey, String userId,
                                                  Integer startNum, Integer pageSize);

    /**
     * 查询流程历史实例
     * @param processInstanceId
     * @return
     */
    HistoricProcessInstance getHistoricProcessInstanceById(String processInstanceId);
    /**
     * 获取已办任务个数
     * @param definitionKey
     * @param userId
     * @return
     */
    Long selectDoneTaskCount(String definitionKey, String userId);

    /**
     * 查询节点审核历史
     * @param instanceId
     * @return
     */
    List<HistoricActivityInstance> selectHistoryList(String instanceId);

    /**
     * 获取节点审批备注
     * @param taskId
     * @return
     */
    String getTaskComment(String taskId);
}
